import json

import requests

url = "https://qianfan.baidubce.com/v2/app/conversation"

payload = json.dumps({
    "app_id": "5eb075e9-8551-4357-8534-5dad224eaed7"
})
headers = {
    'Content-Type': 'application/json',
    'X-Appbuilder-Authorization': 'Bearer bce-v3/ALTAK-qdOByRlbA0Hhrz4scRjl4/b259a3971f73a10f20d5ab583fb1a1388eafacbf'
}

response = requests.request("POST", url, headers=headers, data=payload)

data = json.loads(response.text)
conversation_id = data['conversation_id']

url = "https://qianfan.baidubce.com/v2/app/conversation/runs"

payload = json.dumps({
    "app_id": "5eb075e9-8551-4357-8534-5dad224eaed7",
    "query": input('请输入问题：'),
    "stream": False,
    "conversation_id": conversation_id
})
headers = {
    'Content-Type': 'application/json',
    'X-Appbuilder-Authorization': 'Bearer bce-v3/ALTAK-qdOByRlbA0Hhrz4scRjl4/b259a3971f73a10f20d5ab583fb1a1388eafacbf'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
data = json.loads(response.text)
answer = data['answer']